#include "base/Packet.h"
#include "util/Logger.h"
#include <cstdio>
#include <cstring>

NEW_DELETE_OPERATORS_CPP(Packet,1);

Packet::Packet (Entity* src, Entity* dst, uint size) :
    source(src),
    destination(dst),
    size(size)
{ }

Packet::Packet (Entity* src, Entity* dst) :
    source(src),
    destination(dst),
    size(1)
{ }

Packet::~Packet () { }

void Packet::swap () {
    Entity* src = getSource();
    setSource(getDestination());
    setDestination(src);
}

char const* Packet::toString() const {
    char * s = const_cast<char*>(string);
    strcpy(s, source ? source->getName() : "<none>");
    strcat(s, "->");
    strcat(s, destination ? destination->getName() : "<none>");
    
    char buffer [20];    
    sprintf(buffer, "{ID:%u}", (uint)this);
    strcat(s, buffer);
    
    return string;
}
